package com.atguigu.demo.excel;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;

import java.util.ArrayList;
import java.util.List;

public class WorkRead extends AnalysisEventListener<Student01> {
    List<Student01> dataList = new ArrayList<>();
    List<Student02> student02List = new ArrayList<>();

    @Override
    public void invoke(Student01 student01, AnalysisContext analysisContext) {
        dataList.add(student01);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }

    public static void main(String[] args) {
        String fileName = "C:\\Users\\Lenovo\\Desktop\\2018级软件工程3班信息表.xlsx";
        WorkRead temp = new WorkRead();
        EasyExcel.read(fileName, Student01.class, temp).sheet("Sheet1 ").doRead();
        for(Student01 item:temp.dataList){
            Student02 student02 = new Student02();
            student02.setClassNo("239312");
            student02.setName(item.getName());
            student02.setSex(item.getSex());
            student02.setStudyNo("G" + item.getSfz());
            temp.student02List.add(student02);
        }
        for(Student02 item:temp.student02List){
            System.out.println(item);
        }
        String writeFileName = "C:\\Users\\Lenovo\\Desktop\\student.xls";
        EasyExcel.write(writeFileName,Student02.class).sheet("Sheet1").doWrite(temp.student02List);
    }
}
